home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / FlyThrough 1.1.2 / src / Source / QD3D General Tools / CObjectMaker.h < prev    next >
Encoding:
Text File  |  1997-03-09  |  927 b   |  45 lines  |  [TEXT/CWIE]

  1. //
  2. //    CObjectMaker.h
  3. //
  4. //    Template class CObjectMaker
  5. //    A template for C++ classes that construct and auto-destruct QuickDraw 3D objects.
  6. //
  7. //    This is an abstract class.
  8. //    Everything is inline, so there is no *.cp file.
  9. //
  10. //    by James Jennings
  11. //    November 26, 1995
  12. //
  13.  
  14. #pragma once
  15.  
  16. // A useful inline function.
  17. inline
  18. void    Q3Forget( TQ3Object & inObject )
  19. {
  20.     if ( inObject != 0 )
  21.         ::Q3Object_Dispose( inObject );
  22.     inObject = 0;
  23. }
  24.  
  25. template <class T>
  26. class CObjectMaker {
  27. protected:
  28.                 CObjectMaker() : mObject(0) {}
  29.     virtual        ~CObjectMaker() { Q3Forget( mObject ); }
  30.     
  31.     virtual void    Make() = 0;
  32. public:
  33.             T        Get() const
  34.                         {    // Get() is normally a const function, 
  35.                             // unless Make() does a defered change.
  36.                             if (!mObject)
  37.                                 const_cast<CObjectMaker<T>*>(this)->Make(); 
  38.                             return mObject;
  39.                         }
  40.             T        GetRef() const
  41.                         { return ::Q3Shared_GetReference( Get() ); }
  42. protected:
  43.     T        mObject;
  44. };
  45.